local wulie = fk.CreateSkill {

  name = "joyex__wulie",

  tags = { Skill.Limited, },

}



wulie:addEffect(fk.TurnStart, {
  name = "joyex__wulie",
  anim_type = "offensive",
  frequency = Skill.Limited,
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    return  target == player and player:hasSkill(wulie.name) and player:usedSkillTimes(wulie.name, Player.HistoryGame) == 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local _, ret = room:askForUseActiveSkill(player, "#joyex__wulie_active", "#joyex__wulie-hp", true)
    local n
    if ret then
      n = ret.interaction
    if n > 0 then
      event:setCostData(self, n)
      return true
    end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = event:getCostData(self)
    room:loseHp(player,n,wulie.name)
    if not player.dead then
      room:addPlayerMark(player,"@joyex__lie",n)
      local targets = room:askForChoosePlayers(player,table.map(room:getOtherPlayers(player),function(p) return p.id end),1,n,"#joyex__wulie:::"..n,wulie.name,true)
      if #targets > 0 then
        for _, pid in ipairs(targets) do
          local p = room:getPlayerById(pid)
          room:addPlayerMark(p,"@joyex__lie",1)
        end
      end
    end
  end,
})

wulie:addEffect("active", {
  name = "#joyex__wulie_active",
  anim_type = "offensive",
  card_num = 0,
  target_num = 0,
  frequency = Skill.Limited,
  interaction = function(self,player)
    return UI.Spin {
      from = 1,
      to = player.hp,
    }
  end,
})

wulie:addEffect(fk.DamageCaused, {
  name = "#joyex__wulie_buff",
  anim_type = "offensive",
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return  data.to == player and player:getMark("@joyex__lie") > 0
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player,wulie.name,nil,"#joyex__wulie_buff2")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:removePlayerMark(player,"@joyex__lie",1)
    return true
  end,
})

return wulie